<template>
    <div>
      <h2>测试axios的get请求;获取对应仓库的所有issues</h2>
      <ul>
        <li v-for="issue in issues" :key="issue.id">
          <span>{{issue.title}}</span>
        </li>
      </ul>
    </div>
</template>

<script>
    import axios from 'axios'
    export default {
        name: "testGet",
        data(){
          return {
            issues:[]
          }
        },
        async mounted(){
          /*const body = await axios({
              method: 'get',
              baseURL:"https://api.github.com",//基地址
              url: '/repos/betterDamu/sh_200318/issues',
              params: {
                name: "damu666"
              },
              timeout:10000
          });*/

          /*const body = await axios('/repos/betterDamu/sh_200318/issues',{
            method: 'get',
            baseURL:"https://api.github.com",//基地址
            params: {
              name: "damu666"
            },
            timeout:10000
          });*/


          //Promise.all实现并发请求
          var p1 = axios({
            baseURL:"https://api.github.com",//基地址
            url: '/repos/betterDamu/sh_200318/issues2',
            params: {
              name: "damu666"
            },
            timeout:10000
          });
          var p2 = axios({
            baseURL:"https://api.github.com",//基地址
            url: '/search/users',
            params: {
              q: "damu"
            },
            timeout:10000
          });
          // var body = await Promise.all([p1,p2])

          //竞争请求
          // var body = await Promise.race([p1,p2])

          //axios提供的并发请求方案
          /*axios.all([p1,p2]).then(axios.spread((a,b)=>{
            console.log(a);
            console.log(b);
          }))*/


          this.issues = body.data;
        }
    }
</script>

<style scoped>

</style>
